﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ChurchData.Business;

namespace ChurchData.Utility
{
    public partial class SqlForm : Form
    {
        public SqlForm()
        {
            InitializeComponent();
        }

        private void btnExecute_Click(object sender, EventArgs e)
        {
            try
            {
                string sql = (txtSql.SelectedText.Trim().Length > 0) ? txtSql.SelectedText.Trim() : txtSql.Text.Trim();
                DataSet ds = ChurchDataBusinessBase.GetDataSet(sql);
                if (ds.Tables.Count > 0)
                    grdResults.DataSource = ds.Tables[0];
                else
                    MessageBox.Show("Success");
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }
        }

        private void SqlForm_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F5)
            {
                btnExecute.PerformClick();
            }
        }
    }
}
